Contents

Last modified: 2021-08-31 16:05:43
Compiled: Tue Aug 31 16:05:45 2021

1 Getting started

#Load package
library(rMiW)
library(EBImage)

2 Import a kidney image from rMiW

The displayed image (`Mouse01_Kid_x20_z0_RR01.png’) is an image of whole slide imaging (WSI) for observing the mouse P0 kidney tissue stained by H&E.

file <- system.file("extdata", "Mouse01_Kid_x20_z0_RR01.png", package="rMiW")

#Visualization
EBImage::display(EBImage::readImage(files = file), method = "raster")
Mouse01_Kid_x20_z0_RR01.png

Figure 1: Mouse01_Kid_x20_z0_RR01.png

3 Basic image processing

3.1 Convert to the grey image

#Read image
Img <- EBImage::readImage(files = file)

#Convert to the gray image
GrayImg <- toGrayScale(Img, mode = "luminance")

#Visualization
EBImage::display(GrayImg, method = "raster")
The gray image of Mouse01_Kid_x20_z0_RR01.png

Figure 2: The gray image of Mouse01_Kid_x20_z0_RR01.png

3.2 Resize the image

#1% area size
Img10 <- EBImage::resize(Img, w = round(dim(Img)[1]*0.1, 0), filter = "bilinear")

#6% area size
Img25 <- EBImage::resize(Img, w = round(dim(Img)[1]*0.25, 0), filter = "bilinear")

#25% area size
Img50 <- EBImage::resize(Img, w = round(dim(Img)[1]*0.5, 0), filter = "bilinear")

#50% area size
Img70 <- EBImage::resize(Img, w = round(dim(Img)[1]*0.707, 0), filter = "bilinear")

#Visualization
par(mfrow=c(2,2))
EBImage::display(Img10, method = "raster")
text(x = dim(Img10)[1]/20, y = dim(Img10)[2]/10, label = "1% area size", adj = c(0,0), col = "black", cex = 1.5)
EBImage::display(Img25, method = "raster")
text(x = dim(Img25)[1]/20, y = dim(Img25)[2]/10, label = "6% area size", adj = c(0,0), col = "black", cex = 1.5)
EBImage::display(Img50, method = "raster")
text(x = dim(Img50)[1]/20, y = dim(Img50)[2]/10, label = "25% area size", adj = c(0,0), col = "black", cex = 1.5)
EBImage::display(Img70, method = "raster")
text(x = dim(Img70)[1]/20, y = dim(Img70)[2]/10, label = "50% area size", adj = c(0,0), col = "black", cex = 1.5)
The resized images of Mouse01_Kid_x20_z0_RR01.png

Figure 3: The resized images of Mouse01_Kid_x20_z0_RR01.png

3.3 Transpose the image

#Transpose the image
ImgTrans <- EBImage::transpose(Img)

#Flip or flop the image
Imgflip <- EBImage::flip(Img)
Imgflop <- EBImage::flop(Img)

#Visualization
par(mfrow=c(2,2))
EBImage::display(Img, method = "raster")
text(x = dim(Img)[1]/20, y = dim(Img)[2]/10, label = "Original", adj = c(0,0), col = "black", cex = 1.5)
EBImage::display(ImgTrans, method = "raster")
text(x = dim(ImgTrans)[1]/20, y = dim(ImgTrans)[2]/10, label = "Transpose", adj = c(0,0), col = "black", cex = 1.5)
EBImage::display(Imgflip, method = "raster")
text(x = dim(Imgflip)[1]/20, y = dim(Imgflip)[2]/10, label = "Flip", adj = c(0,0), col = "black", cex = 1.5)
EBImage::display(Imgflop, method = "raster")
text(x = dim(Imgflop)[1]/20, y = dim(Imgflop)[2]/10, label = "Flop", adj = c(0,0), col = "black", cex = 1.5)
The rotated images of Mouse01_Kid_x20_z0_RR01.png

Figure 4: The rotated images of Mouse01_Kid_x20_z0_RR01.png

4 Basic clustering using k-means

k: 2~5 - 1x1 - 2x2 - 5x5

Session information

## R version 4.1.0 (2021-05-18)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Catalina 10.15.7
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] ja_JP.UTF-8/ja_JP.UTF-8/ja_JP.UTF-8/C/ja_JP.UTF-8/ja_JP.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] BiocStyle_2.20.2
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.7          RColorBrewer_1.1-2  bslib_0.2.5.1      
##  [4] compiler_4.1.0      BiocManager_1.30.16 jquerylib_0.1.4    
##  [7] highr_0.9           base64enc_0.1-3     keras_2.6.0        
## [10] bitops_1.0-7        tools_4.1.0         zeallot_0.1.0      
## [13] digest_0.6.27       jsonlite_1.7.2      evaluate_0.14      
## [16] lattice_0.20-44     png_0.1-7           rlang_0.4.11       
## [19] Matrix_1.3-4        magick_2.7.3        yaml_2.2.1         
## [22] parallel_4.1.0      xfun_0.25           fastmap_1.1.0      
## [25] DiagrammeR_1.0.6.1  stringr_1.4.0       knitr_1.33         
## [28] generics_0.1.0      sass_0.4.0          fftwtools_0.9-11   
## [31] htmlwidgets_1.5.3   locfit_1.5-9.4      grid_4.1.0         
## [34] reticulate_1.20     glue_1.4.2          R6_2.5.1           
## [37] rMiW_0.99.1         jpeg_0.1-9          rmarkdown_2.10     
## [40] bookdown_0.23       whisker_0.4         magrittr_2.0.1     
## [43] tfruns_1.5.0        htmltools_0.5.2     BiocGenerics_0.38.0
## [46] abind_1.4-5         EBImage_4.34.0      tiff_0.1-8         
## [49] tensorflow_2.6.0    stringi_1.7.4       visNetwork_2.0.9   
## [52] RCurl_1.98-1.4